﻿using System;

namespace QuadraticEquation
{
    public class SolutionEquation
    {
        const double EPS = 0.001;
        private double x1;
        private double x2;
        private int count;

        public double GetX1()
        {
            return x1;
        }

        public double GetX2()
        {
            return x2;
        }

        public double GetCount()
        {
            return count;
        }

        public void SetX1( double x1)
        {
            this.x1 = x1;
        }

        public void SetX2(double x2)
        {
            this.x2 = x2;
        }

        public void SetCount(int count)
        {
            this.count = count;
        }

        public SolutionEquation(double x1, double x2)
        {
            this.x1 = x1;
            this.x2 = x2;
            count = 2;
        }

        public SolutionEquation(double x1)
        {
            this.x1 = x1;
            this.x2 = x1;
            count = 1;
        }

        public SolutionEquation()
        {
            count = 0;
        }

        public bool Equals(SolutionEquation solutionEquation)
        {
            return ((Math.Abs(this.x1 - solutionEquation.x1) < EPS) && (Math.Abs(this.x2 - solutionEquation.x2) < EPS) && (this.count == solutionEquation.count)) ||
                   ((Math.Abs(this.x1 - solutionEquation.x2) < EPS) && (Math.Abs(this.x2 - solutionEquation.x1) < EPS) && (this.count == solutionEquation.count)) ||
                   (this.count == solutionEquation.count) && (this.count == 0);
        }
    }

    public class SolvingQuadraticEquation
    {
        public SolvingQuadraticEquation() { }

        public SolutionEquation solve(double a, double b, double c)
        {
            //a*x*x+b*x+c=0
            if (a == 0) 
            { 
                return new SolutionEquation();
            }
            b /= a;
            c /= a;
            a = 1;

            double d = Math.Sqrt(b * b - 4 * a * c);
            SolutionEquation solutionEquation;
            if (d > 0)
            {
                solutionEquation = new SolutionEquation((-b - d) / 2, (-b + d) / 2);
            }
            else if (d == 0)
            {
                solutionEquation = new SolutionEquation(-b / 2);
            }
            else
            {
                solutionEquation = new SolutionEquation();
            }

            return solutionEquation;
        }
    }
}
